#include "atomic_op_asm.h"

ENTRY_NP(_atomic_nand_64)
	mov	x4, x0
1:	ldxr	x0, [x4]		/* load old value (to be returned) */
	mvn	x2, x0			/* complement source */
	and	x2, x2, x1		/* calculate new value */
	stxr	w3, x2, [x4]		/* try to store */
	cbnz	w3, 1b			/*   succeed? no, try again */
	dmb	st
	ret				/* return old value */
END(_atomic_nand_64)

ATOMIC_OP_ALIAS(atomic_nand_64,_atomic_nand_64)
ATOMIC_OP_ALIAS(atomic_nand_ulong,_atomic_nand_64)
STRONG_ALIAS(__sync_fetch_and_nand_8,_atomic_nand_64)
STRONG_ALIAS(_atomic_nand_ulong,_atomic_nand_64)

ENTRY_NP(_atomic_nand_64_nv)
	mov	x4, x0			/* need r0 for return value */
1:	ldxr	x0, [x4]		/* load old value */
	mvn	x0, x0			/* complement source */
	and	x0, x0, x1		/* calculate new value (return value) */
	stxr	w3, x0, [x4]		/* try to store */
	cbnz	w3, 1b			/*   succeed? no, try again? */
	dmb	st
	ret				/* return new value */
END(_atomic_nand_64_nv)

ATOMIC_OP_ALIAS(atomic_nand_64_nv,_atomic_nand_64_nv)
ATOMIC_OP_ALIAS(atomic_nand_ulong_nv,_atomic_nand_64_nv)
STRONG_ALIAS(__sync_nand_and_fetch_8,_atomic_nand_64_nv)
STRONG_ALIAS(_atomic_nand_ulong_nv,_atomic_nand_64_nv)
